from common.request import JsonResponse, _Root
from dota.models import DotaFunctioneer, Video


class _Functioneer(_Root):

    def get(self):
        name = self.GET.get('name', '')
        if name == '':
            user_set = self.db.query(DotaFunctioneer).all()
            self.db.commit()
        else:
            user_set = self.db.query(DotaFunctioneer).filter(DotaFunctioneer.name.like('%' + name + '%')).all()
            self.db.commit()
        user_list = []
        for user_row in user_set:
            user_dict = user_row.jn('id', 'name', 'decription', 'icon')
            user_list.append(user_dict)
        return JsonResponse(self, '50000', data=user_list)
